home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------------------------------
-
- FILENAME
- PrintDialogMessage.c
-
- DESCRIPTION
- This file contains the message procedure that will be invoked when the Printing Manager
- issues the PrintDialog message. The routine which is called is PrintDlgMessageProc.
- This routine calls SetUpAdditionsDlgPanel to add the Additions dialog panel to the
- Print Dialog and to define the routines to call in order to process item hits and
- events in the panel.
-
- The Additions panel utilizes an the Print Dialog's 'xdtl' capability to automatically
- check/uncheck the buttons in the dialog. It does, however, also provide an event filter
- procedure (PanelFilterMessageProc) and an item hit procedure (PanelEventMessageProc) for performing
- actions above and beyond those provided by the 'xdtl' facility.
-
- COPYRIGHT
- Copyright Apple Computer, Inc. 1991 - 1996
- All rights reserved.
-
- INTERFACE ROUTINES
- PrintDlgMessageProc
-
- MODIFICATION HISTORY
- 05/15/91 ALA Initial Implementation
- 06/15/93 Sam Weiss GetMyResFile -> GetMessageHandlerResFile
- 6/14/96 cn Updated to support Universal Interfaces 2.1.
-
-
-
- ------------------------------------------------------------------------------- */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Dialogs.h>
- #include <TextEdit.h>
- #include <OSUtils.h>
- #include <Packages.h>
- #include <ToolUtils.h>
- #include <Menus.h>
- #include <String.h>
- #include <Strings.h>
- #include <Printing.h>
-
- #include <GXGraphics.h>
- #include <GraphicsLibraries.h>
- #include <FontLibrary.h>
-
- #include <Collections.h>
- #include <GXMessages.h>
-
- #include <GXPrinting.h>
-
- #include "Utilities.h"
- #include "Additions.h"
-
-
- /*==================================== CONSTANTS ====================================*/
-
-
- /* ===== Dialog 'ppnl' related constants ===== */
-
- #define kAdditionsPanelResID gxPrintingExtensionBaseID /* Resource ID of the Addition's 'ppnl' resource */
-
-
- /* ===== Dialog panel 'DITL' constants ===== */
-
- #define diAddPageBorder 2 /* Add page border to each page item */
- #define diSerializeCopies 3 /* Serialize all printed copies item */
- #define diAddCoverPage 4 /* Add a cover page item */
- #define diCoverPageFirst 5 /* Add cover page at beginning item */
- #define diCoverPageLast 6 /* Add cover page at end item */
- #define diStartCopynum 7 /* Starting copy number for serialization */
-
-
- /* ===== Dialog panel 'ICN#' constants ===== */
-
- #define kCoverPageOnTop gxPrintingExtensionBaseID /* Cover page icon with the cover page on top */
- #define kCoverPageOnBott gxPrintingExtensionBaseID + 1 /* Cover page icon with the cover page on bottom */
-
-
- /*================================ INTERNAL ROUTINES ================================*/
-
-
- /* ===== OpenAdditionsPanel =====
-
- Processes the panel dialog Open message for the extension's panel. It assumes a SetPort
- has already been performed.
- */
- void OpenAdditionsPanel( // (out) Error code
- DialogPtr pDlg, // (in) Pointer to the Print dialog
- short itemCount) // (in) Number of ditl items before our panel's dialog items
- {
- Boolean coverPageOn;
-
- /* Enable/disable the cover page radio buttons depending upon whether Cover Page is checked */
-
- coverPageOn = CheckBoxIsOn(pDlg, itemCount + diAddCoverPage);
- EnableControlOnOff(pDlg, itemCount + diCoverPageFirst, coverPageOn);
- EnableControlOnOff(pDlg, itemCount + diCoverPageLast, coverPageOn);
-
- /* Force the Cover Page icons to be drawn */
- {
- short itemType;
- Rect itemRect;
- Handle hItem;
-
- GetDItem(pDlg, itemCount + diCoverPageFirst, &itemType, &hItem, &itemRect);
- itemRect.top -= 8;
- itemRect.bottom += 8;
- itemRect.left = itemRect.right;
- itemRect.right = itemRect.left + 32;
- InvalRect(&itemRect);
-
- GetDItem(pDlg, itemCount + diCoverPageLast, &itemType, &hItem, &itemRect);
- itemRect.top -= 8;
- itemRect.bottom += 8;
- itemRect.left = itemRect.right;
- itemRect.right = itemRect.left + 32;
- InvalRect(&itemRect);
- }
- }
- /* OpenAdditionsPanel */
-
-
- /* ===== PanelFilterMessageProc =====
-
- Processes the panel dialog Filter event message for the extension's panel.
- */
-
- OSErr PanelFilterMessageProc(
- gxPanelInfoRecord *panelInfo, /* (in) Pointer to the Print panel info. */
- Boolean *weDidEvent) /* (out) true => panel processed the event; false => Printing Manager should handle it */
- {
- #pragma unused ( unused )
-
-
- *weDidEvent = false;
-
- if (panelInfo->theEvent->what == updateEvt) /* T => May draw the cover page icons */
- {
- /* Only draw the icons if it's our window */
- if ( panelInfo->pDlg == (DialogPtr) panelInfo->theEvent->message )
- {
- short itemType;
- Rect itemRect;
- Handle hItem;
- Handle theIcon;
-
- GetDItem(panelInfo->pDlg, panelInfo->itemCount + diCoverPageFirst, &itemType, &hItem, &itemRect);
- itemRect.top -= 8;
- itemRect.bottom += 8;
- itemRect.left = itemRect.right + 1;
- itemRect.right = itemRect.left + 32;
-
- theIcon = GetIcon(kCoverPageOnTop);
- if (theIcon != nil)
- {
- PlotIcon(&itemRect, theIcon);
- ReleaseResource(theIcon);
- }
-
- GetDItem(panelInfo->pDlg, panelInfo->itemCount + diCoverPageLast, &itemType, &hItem, &itemRect);
- itemRect.top -= 8;
- itemRect.bottom += 8;
- itemRect.left = itemRect.right + 1;
- itemRect.right = itemRect.left + 32;
-
- theIcon = GetIcon(kCoverPageOnBott);
- if (theIcon != nil)
- {
- PlotIcon(&itemRect, theIcon);
- ReleaseResource(theIcon);
- }
- }
- }
- /* else - some other type of event */
-
- return(*weDidEvent);
- }
- /* PanelFilterMessageProc */
-
-
- /* ===== PanelEventMessageProc =====
-
- Processes the panel dialog ItemHit message for the extension's panel. Note that we rely
- on the 'xdtl' capability of the Print Dialog to save the new settings in the
- Additions collection item (this is why the routine doesn't process the kPanelConfirmEvt
- message.
- */
- OSErr PanelEventMessageProc( /* (out) special Print panel error code */
- gxPanelInfoRecord *panelInfo, /* (in) Pointer to the Print panel info. */
- gxPanelResult *unused)
- {
-
- #pragma unused ( unused )
-
- OSErr anErr = noErr;
- GrafPtr oldPort;
- DialogPtr pDlg;
-
- pDlg = panelInfo->pDlg;
-
- GetPort(&oldPort);
- SetPort(pDlg);
-
- /* Determine the type of hit message we received */
- switch (panelInfo->panelEvt)
- {
- case gxPanelOpenEvt:
- OpenAdditionsPanel(pDlg, panelInfo->itemCount);
- break;
-
- case gxPanelHitEvt:
- {
- short whichItem;
-
- /* If the cover page check box was clicked, enable the cover page radio buttons */
-
- whichItem = panelInfo->itemHit - panelInfo->itemCount;
- if ( whichItem == diAddCoverPage )
- {
- Boolean radiosEnabled;
-
- radiosEnabled = CheckBoxIsOn(pDlg, panelInfo->itemHit);
-
- EnableControlOnOff(pDlg, panelInfo->itemCount + diCoverPageFirst, radiosEnabled);
- EnableControlOnOff(pDlg, panelInfo->itemCount + diCoverPageLast, radiosEnabled);
- }
- break;
- }
-
- case gxPanelActivateEvt:
- case gxPanelDeactivateEvt:
- case gxPanelIconFocusEvt:
- case gxPanelPanelFocusEvt:
- {
- /* Activate/deactivate the serial number edit text field if it's the current edit text field */
- if ( (((DialogPeek) pDlg)->editField + 1) == (panelInfo->itemCount + diStartCopynum) )
- {
- if ( (panelInfo->panelEvt == gxPanelIconFocusEvt) ||
- (panelInfo->panelEvt == gxPanelDeactivateEvt)
- ) // T => Deactivate the TE field
- TEDeactivate(((DialogPeek) pDlg)->textH);
- else
- TEActivate(((DialogPeek) pDlg)->textH);
- }
- break;
- }
- }
-
- SetPort(oldPort);
-
- return(anErr);
- }
- /* DoJobPanelItemHit */
-
-
- /* ===== SetUpAdditionsDlgPanel =====
-
- SetUpAdditionsDlgPanel adds the Additions dialog panel to the Print dialog.
- */
- OSErr SetUpAdditionsDlgPanel( // (out) error code
- gxJob printJob, // (in) the Job reference for the job we're printing
- short additionsResFile) // (in) refnum of the Additions file
- {
- OSErr anErr = noErr;
- Collection jobCollection;
- gxPanelSetupRecord thePanelInfo;
- AdditionsCollection additionsConfig;
-
- /* Get a reference to the job's collection */
- jobCollection = GXGetJobCollection(printJob);
-
- /* See if the Addition's collection item exists. If the item already exists, then */
- /* we'll use the last settings. */
- anErr = GetCollectionItem (jobCollection,
- kAdditionsCollectionType,
- gxPrintingTagID,
- nil,
- &additionsConfig);
-
- if (anErr == collectionItemNotFoundErr) // T => Item doesn't exist; add it
- {
- /* Initialize what will be the initial dialog settings */
- additionsConfig.nextEndSerialNum = 1;
- additionsConfig.coverPage = kCoverPageFirst;
- additionsConfig.addPageBorder = false;
- additionsConfig.serializeCopies = false;
- additionsConfig.addCoverPage = false;
-
- /* Add the Additions collection item */
- anErr = AddCollectionItem( jobCollection,
- kAdditionsCollectionType,
- gxPrintingTagID,
- sizeof(AdditionsCollection),
- &additionsConfig);
- }
-
- if (anErr == noErr)
- {
- /* Initialize the dialog panel structure */
- thePanelInfo.panelResId = kAdditionsPanelResID;
- thePanelInfo.resourceRefNum = additionsResFile;
- thePanelInfo.refCon = 0;
- thePanelInfo.panelKind = gxExtensionPanel;
-
- /* Add the dialog panel to the Print dialog */
- anErr = GXSetupDialogPanel(&thePanelInfo);
- }
-
- return(anErr);
- }
- /* SetUpAdditionsDlgPanel */
-
-
- /*================================== MESSAGE INTERFACE ROUTINE ==================================*/
-
-
- /* ===== PrintDlgMessageProc =====
-
- PrintDlgMessageProc is the extension's routine which will be invoked when Printing issues a
- PrintDialog message. This routine will call SetUpAdditionsDlgPanel to add a dialog panel to the
- Print dialog. The user can use that panel to select the additive effects to be added
- to the document pages. The effects selected are recorded in a AdditionsCollection record and
- stored with the Job collection. At despooling and rendering time, this configuration is retrieved and
- the page filtered based upon the configuration's settings.
- */
- OSErr PrintDlgMessageProc( // (out) Error code
- gxDialogResult *result)
- {
-
- OSErr anErr;
-
- /* Add the Filter's panel to the Print dialog */
- anErr = SetUpAdditionsDlgPanel(GXGetJob(), GXGetMessageHandlerResFile());
- if (anErr == noErr)
- {
- /* Pass the PrintDialog message on to others */
- anErr = Forward_GXJobPrintDialog(result);
- }
-
- return(anErr);
- }
- /* PrintDlgMessageProc */
-